const app = getApp()
import {
  HomeIndex
} from 'index-modal.js';
import {
  Config
} from '../../../utils/config.js';
var Function = require("../../../utils/function.js");
var index = new HomeIndex(); //实例化 首页 对象;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    is_hide:false,
    isnth:true,  //是否领取
    url: Config.Url,
    receiveState:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  //获取领取好友邀请优惠券后的页面
  get_friend:function(){
    let that=this;
    let data={
      uid: wx.getStorageSync('members').id
    }
    index.get_friend(data,(res)=>{
      if(res.code==200 && res.data){
        that.setData({
          friendList:res.data,
          receiveState:false
        })
      }
    })
  },

  //去首页
  toIndex:function(){
    let that=this;
    wx.switchTab({
      url: '/pages/shouye/index/index'
    })
  },


  getback(){
    let that =this;
    let data = {
      top_id: wx.getStorageSync('topid'),
      // top_id: wx.getStorageSync('topid'),
      uid: wx.getStorageSync('members').id
    }
    index.getback(data,(res)=>{
      if(res.code == 200){
        if(res.data == null){
          that.setData({
            isnth:false
          })
        }
        
        that.setData({
          count: res.count,
          title:res.data,
          receiveState:false
        })
      }else{
        that.setData({
          title: '',
          count: res.data,
        })
      }
    })
  },

  linqu(){
    let that = this;
    let data ={
      uid:wx.getStorageSync('members')['id']
    }
    index.baibai(data,(res)=>{
        if(res.code == 200){
          wx.showToast({
            title: res.msg,
            duration:1000,
            icon:'none'
          })
          that.setData({
            receiveState: false
          })
          that.getback();
          setTimeout(function(){
            that.get_friend();
          },800)
          // setTimeout(()=>{
          //   wx.navigateTo({
          //     url: '../frend3/frend3',
          //   })
          // },1000)
        }else{
          wx.showToast({
            title: res.msg,
            duration: 1000,
            icon: 'none'
          })
        }
    })
  },

  //邀请好友页面的视频
  config:function(){
    let that=this;
    index.config((res)=>{
      if(res.code==200){
        that.setData({
          new_coupon: res.data.new_coupon,
          friend_video: res.data.friend_video,
          reward: res.data.reward,
          friend_money:res.data.friend_money
        })
      }
    })
  },

  

  showModal() {this.setData({ is_hide: true})},
  hideModal() {this.setData({ is_hide:false})},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that=this;
    this.config();
    this.getback()
    that.get_friend();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})